<extend name="common:base"/>
<block name="content">
    <div id="header">
        <div class="header">
            <h1 class="tit">订单详情</h1>
        </div>
    </div>
    <input type="hidden" value="{$orderThrough['price']}" id="order_total">
    <neq name="Think.session.user_id" value="$order['uid']"><input type="hidden" value="{$sum}" id="price_sum"></neq>
    <input type="hidden" value="{$rank_id}" id="top_rank">
    <input type="hidden" value="{$order['id']}" id="order_id">


    <div class="ddxq-a">
        <div class="ddxq-aa">
            <img src="{:C('__STATIC__')}{:C('DEFAULT_THEME')}/Static/img/ddxq-ad.jpg" class="ddxq-img1">
            <div class="ddxq-right">
                <div class="ddxq-right-1">
                    <span>收货人：<a>{$order['consignee']}</a></span>
                    <span><a>{$order['phone']}</a></span>
                </div>
                <div class="ddxq-right-2">
                    <span>收货地址&nbsp;:&nbsp;</span>
                    <a>{$order['detail_area']}</a>
                </div>
                <div class="ddxq-right-3">
                    <span>留言&nbsp;:&nbsp;</span>
                    <a>{$order['message']}</a>
                </div>
            </div>
        </div>
    </div>
    <div class="ddxq-b">
        <div class="ddxq-bb">
            <p class="ddxq-p1">元典科技</p>

            <volist name="orderGood" id="vo">
                <input type="hidden" name="brand_id" value="{$vo['brand_id']}" id="brand_id">
                <span href="">
                    <!--{:U('Good/goodsdetail' ,array('id'=>$vo['id']))}-->
                    <div class="ddxq-div1">
                        <img class="good_img" src="{$vo.img}"/>
                        <div class="ddxq-title">
                            <p class="good_name">{$vo['g_name']}</p>
                            <p>{$vo['spec_str']}</p>
                            <p class="ddqx-title-p">
                                <span>¥
                                    <!--<if condition="$vo['good_type'] eq 2">-->
                                    <!--<span class="good_price">{$vo['batch_amt']}/箱</span>-->
                                    <!--</if>-->
                                    <if condition="$vo['good_type'] eq 1">
                                    <span class="good_price">{$vo['unit_amt']}/件</span>
                                    </if>
                                    <if condition="$vo['good_type'] eq 0">
                                    <span class="good_price">{$vo['price']}</span>
                                    </if>
                                </span>
                                <span>× <span class="good_num">{$vo['num']}</span></span>
                            </p>
                            <if condition="$vo.order_status eq 1"><span class="back_money">退款中</span></if>
                            <if condition="$vo.order_status eq 2"><span class="back_money">退款成功</span></if>
                            <if condition="$vo.order_status eq 3"><span class="back_money">退款失败</span></if>
                            <eq name="Think.session.user_id" value="$order['uid']">
                                <!--<if condition="$order['is_pay'] eq 1" >-->
                                    <eq name="order['is_pay']" value="1">
                                        <if condition="$vo.order_status eq 0 AND $order['status'] eq 0 AND $order['is_platform'] eq 1 AND $vo.is_back eq 0">
                                     <a href="{:U('Order/back_money',array('order_id'=>$order['id'],'good_id'=>$vo['id']))}"><span class="back_money">退款</span></a>
                                        </if>
                                         <if condition="$vo.order_status eq 0 AND $order['status'] eq 0 AND $order['is_platform'] eq 1 AND $vo.is_back eq 1">
                                         <span class="sb">{$vo.noback_reason}</span>
                                        </if>
                                    </eq>
                                <!--</if>-->
                            </eq>
                        </div>
                        <input type="hidden" id="good_id" value="{$vo['id']}">
                    </div>
                </span>
            </volist>

            <div class="ddxq-div2">
                <p>订单号：<a>{$order['order_id']}</a></p>
                <p>下单时间：<a>{$order['time']|date='Y-m-d H:i:s',###}</a></p>
            </div>
            <notempty name="agent_name">
                <div class="ddxq-div3"><p>发货人：<a>{$agent_name}</a></p></div>
            </notempty>
            <if condition="$order['is_top'] eq 1 AND $order['is_deliver'] eq 1">
                <div class="ddxq-div3"><p>发货人：<a>平台发货</a></p></div>
            </if>
            <notempty name="order['code_num']">
                <div class="ddxq-div3"><p>快递号：<a>{$order['code_num']}</a></p></div>
            </notempty>

            <div class="ddxq-div3">
                <p>我的余额：<a>
                    <if condition="$brand_money neq 0">{$brand_money}元
                        <else/>
                        余额为0，请尽快充值
                    </if>
                </a></p>
            </div>
            <div class="ddxq-div3"><p>配送方式：<a>{$send_type[$order['send_type']]}（{$order['freight_price']}元）</a></p>
            </div>
            <!--<div class="ddxq-div3"><p>支付方式：<a>{$pay_type[$order['pay_type']]}（{$order['service_price']}元）</a></p></div>-->
            <if condition="$order['status'] neq -1 AND $order['is_pay'] eq -1">
                <eq name="Think.session.user_id" value="$order['uid']">
            <div class="ddxq-div3 qrdd-liuyan">
                <p>支付方式：</p>
                <select id="p_type" class="pay-type" style="margin-top: 10px;">
                    <option value="">请选择</option>
                    <foreach name="pay_type" item="t">
                        <option value="{$t.p_id}">{$t.p_name}</option>
                    </foreach>
                </select>
                <span style="color: red;font-size: 0.28rem;line-height: 0.8rem;display: none" class="process">(手续费:<span id="pay_price"></span>元)</span>
            </div>
                </eq>
            </if>

            <notempty name="order['not_agree_reason']">
                <div class="ddxq-div3"><p>驳回原因：<a>{$order['not_agree_reason']}</a></p></div>
            </notempty>

            <if condition="$Think.session.user_id neq $order['uid'] AND $order['is_deliver'] neq 1 AND $orderThrough['state'] neq 1 AND $order['is_pay'] eq 1">
                <div class="ddxq-div3">
                    <p>发货类型：
                        <a>
                            <select name="delivery_type" class="delivery_type">
                                <notempty name="brand">
                                    <option value="1">本人发货</option>
                                </notempty>
                                <option value="2">上级发货</option>
                            </select>
                        </a>
                    </p>
                </div>
            </if>

            <div class="ddxq-div3 nonexian">
                <p>共<a class="ddxq-gray">{$ordercount}</a>样商品&nbsp;&nbsp;小计：
                    <a class="ddxq-red">￥:<span id="pay_money">{$order['price']}</span>(含运费)</a>
                </p>
            </div>
        </div>
    </div>
    <input type="hidden" id="order_p" value="{$order['price']}">
    <input type="hidden" id="order_d" value="{$order['discount']}">
    <input type="hidden" id="order_s" value="{$sum}">
    <input type="hidden" id="order_f" value="{$order['freight_price']}">
    <input type="hidden" id="me" value="{$uid}">
    <input type="hidden" id="order_u" value="{$order['uid']}">
    <div class="ddxq-c">
        <div class="ddxq-c2">
            <!--<a>删除订单</a>-->
            <!--<a>-->
            <eq name="Think.session.user_id" value="$order['uid']">
                <if condition="$order['is_pay'] eq -1">
                    <if condition="$order['status'] neq -1">
                        <a id="cancel">取消订单</a>
                        <a id="confirm">去付款</a>
                        <a id="confirm_show" style="display: none;">付款中....</a>
                    </if>
                </if>
                <else/>
                <if condition="$order['is_pay'] eq 1 AND $order['is_deliver'] neq 1 AND $orderThrough['state'] neq 1">
                    <a style="display: none;">提交</a>
                    <a id="audit_d">提交</a>
                    <a id="show" style="display:none;">提交中....</a>
                    <elseif condition="$order['is_pay'] eq -1"/>
                    <a type="submit">付款后可操作</a>
                </if>
            </eq>
            <if condition="($Think.session.user_id eq $order['uid']) AND ($order['is_deliver'] eq 1) AND ($order['status'] eq 0)">
                <a id="confirm_good">确认收货</a>
            </if>
        </div>
    </div>
    <div id="jump_pay"></div>

</block>
<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/total.css" />
</block>
<block name="JS">
    <script type="text/javascript">
        $(function () {
            //提交
            $('#audit_d').click(function () {
                var val = $(".delivery_type").val();
                if (val == 2) { // two
                    $("#audit_d").hide();
                    $("#show").show();
                    $.ajax({
                        url: "{:U('Order/confirm')}",
                        type: 'post',
                        data: {
                            iid: $('#order_id').val(),
                            price: $('#price_sum').val(),
                            rank_id: $('#top_rank').val()
                        },
                        success: function (msg) {
                            if (msg == -1) {
                                layer.msg('余额不足,请充值!', { time: 1000});
                                $("#audit_d").show();
                                $("#show").hide();
                            } else {
                                layer.msg('提交成功!', { time: 1000});
                                setTimeout(function () {
                                    location.reload(true);
                                }, 1000);
                            }
                        }
                    });
                } else { // one
                    layer.prompt({title: '请输入发货单号', formType: 3}, function (pass, index) {
                        $("#audit_d").hide();
                        $("#show").show();
                        $.ajax({
                            url: "{:U('Order/my_deliver')}",
                            type: 'post',
                            data: {
                                order_id: $('#order_id').val(),
                                price_sum: $('#price_sum').val(),
                                code_num: pass
                            },
                            success: function (msg) {
                                window.location.reload();
                            }
                        });
                    });
                }
            });

            //下单人付款
            $('#confirm').click(function () {
                var pay_type = $("#p_type").val();
                if(!pay_type){
                    layer.msg("请选择支付方式",{time:1000});return false;
                }
                layer.confirm('您确认要付款吗？', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $("#cancel").hide();
                    $("#confirm").hide();
                    $("#confirm_show").show();
                    $.ajax({
                        url: "{:U('Payment/pay')}",
                        type: 'post',
                        data: {
                            order_id: "{$order['order_id']}",
                            pay_type:$("#p_type").val(),
                            pay_price:$("#pay_price").text()
                        },
                        beforeSend: function() {
                            layer.msg("支付中..");
                        },
                        success: function (data) {
                            if (data.status == "success") {
                                if (data.reload_page == 1) {
                                    layer.msg('支付订单成功!', {time: 1500});
                                    setTimeout(function () {
                                        location.reload(true);
                                    }, 1000);
                                } else {
                                    $("#jump_pay").html(data.msg);
                                    layer.msg("支付跳转中...", {time: 3000});
                                }
                            } else {
                                layer.msg(data.msg, {time: 1500});
                                setTimeout(function () {
                                    location.reload()
                                }, 1500);
                            }
                        }
                    });
                });
            });

            //取消订单
            $('#cancel').click(function () {
                layer.confirm('您确认要取消订单吗？', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $("#confirm").hide();
                    $.ajax({
                        url: "{:U('Order/cancel')}",
                        type: 'post',
                        data: {
                            order_id: $('#order_id').val()
                        },
                        success: function (msg) {
                            if (msg) {
                                layer.msg('取消订单成功!', { time: 1500});
                                setTimeout(function() {
                                  window.location.reload();
                                },1000);
                            }
                        }
                    });
                });
            });

            $('#confirm_good').click(function () {
                layer.confirm('您确认收货了吗？', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: "{:U('Order/confirm_good')}",
                        type: 'post',
                        data: {
                            order_id: $('#order_id').val()
                        },
                        success: function (msg) {
                            if (msg.status == "success") {
                                layer.msg('确认收货成功!', {time: 1500});
                                setTimeout(function() {
                                  window.location.href = "{:U('Order/index')}";
                                }, 1000);
                            } else {
                                layer.msg(msg.msg, {time: 1500});
                            }
                        }
                    });
                });
            });

            $("#p_type").change(function () {
                var order_price =$("#order_p").val();
                var order_discount =$("#order_d").val();
                var order_sum =$("#order_s").val();
                var order_freight =$("#order_f").val();
                var order_uid =$("#order_u").val();
                var my_id =$("#me").val();

                $.ajax({
                    url:"{:U('Order/pay_charge')}",
                    type: 'post',
                    data: {
                        pay_type: $("#p_type").val(),
                        order_id: $("#order_id").val()
                    },
                    success: function (msg) {
                        //清干净
                        $("#pay_price").text('');
                        if(!msg == ''){
                            //填值
                        $("#pay_price").text(msg);
                        $(".process").show();
                        }else{
                        $(".process").hide();
                        }
                        if(order_uid == my_id){
                            var pay_money = (order_price*100 + msg*100 - order_discount*100)/100;
                        }else{
                            var pay_money = (order_sum*100 -order_discount*100+order_freight*100)/100;
                        }
                        $("#pay_money").text(pay_money);
                    }
                })
            })

        });
    </script>
</block>